package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.CaseVaccination;
import com.ruoyi.system.service.ICaseVaccinationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CasePersonalInfo;
import com.ruoyi.system.service.ICasePersonalInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 病例基本信息Controller
 * 
 * @author ruoyi
 * @date 2022-04-03
 */
@Controller
@RequestMapping("/system/CasePersonalInfo")
public class CasePersonalInfoController extends BaseController
{
    private String prefix = "system/CasePersonalInfo";

    @Autowired
    private ICasePersonalInfoService casePersonalInfoService;
    @Autowired
    private ICaseVaccinationService caseVaccinationService;

    @RequiresPermissions("system:CasePersonalInfo:view")
    @GetMapping()
    public String CasePersonalInfo()
    {
        return prefix + "/CasePersonalInfo";
    }

    /**
     * 查询病例基本信息列表
     */
    @RequiresPermissions("system:CasePersonalInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CasePersonalInfo casePersonalInfo)
    {
        startPage();
        List<CasePersonalInfo> list = casePersonalInfoService.selectCasePersonalInfoList(casePersonalInfo);
        return getDataTable(list);
    }

    /**
     * 导出病例基本信息列表
     */
    @RequiresPermissions("system:CasePersonalInfo:export")
    @Log(title = "病例基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CasePersonalInfo casePersonalInfo)
    {
        List<CasePersonalInfo> list = casePersonalInfoService.selectCasePersonalInfoList(casePersonalInfo);
        ExcelUtil<CasePersonalInfo> util = new ExcelUtil<CasePersonalInfo>(CasePersonalInfo.class);
        return util.exportExcel(list, "病例基本信息数据");
    }

    /**
     * 新增病例基本信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存病例基本信息
     */
    @RequiresPermissions("system:CasePersonalInfo:add")
    @Log(title = "病例基本信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CasePersonalInfo casePersonalInfo)
    {
        return toAjax(casePersonalInfoService.insertCasePersonalInfo(casePersonalInfo));
    }

    /**
     * 修改病例基本信息
     */
    @RequiresPermissions("system:CasePersonalInfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CasePersonalInfo casePersonalInfo = casePersonalInfoService.selectCasePersonalInfoById(id);
        mmap.put("casePersonalInfo", casePersonalInfo);
        return prefix + "/edit";
    }

    /**
     * 病例信息详情
     */
    @RequiresPermissions("system:CasePersonalInfo:edit")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap)
    {
        CasePersonalInfo casePersonalInfo = casePersonalInfoService.selectCasePersonalInfoById(id);
        mmap.put("casePersonalInfo", casePersonalInfo);
        CaseVaccination caseVaccination = caseVaccinationService.selectCaseVaccinationById(id);
        mmap.put("caseVaccination", caseVaccination);
        return prefix + "/detail";
    }

    /**
     * 修改保存病例基本信息
     */
    @RequiresPermissions("system:CasePersonalInfo:edit")
    @Log(title = "病例基本信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CasePersonalInfo casePersonalInfo)
    {
        return toAjax(casePersonalInfoService.updateCasePersonalInfo(casePersonalInfo));
    }

    /**
     * 删除病例基本信息
     */
    @RequiresPermissions("system:CasePersonalInfo:remove")
    @Log(title = "病例基本信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(casePersonalInfoService.deleteCasePersonalInfoByIds(ids));
    }
}
